package com.example.sfm.controller.admin;

import com.example.sfm.pojo.vo.ChartDataVO;
import com.example.sfm.pojo.vo.NameValueVO;
import com.example.sfm.result.Result;
import com.example.sfm.service.MetricsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "管理员指标管理", description = "管理员对系统指标的管理接口")
@RestController
@RequestMapping("/admin/metrics")
@RequiredArgsConstructor
public class MetricsController {

    private final MetricsService metricsService;

    // 用户活跃趋势
    @Operation(summary = "获取用户活跃趋势", description = "根据指定的天数获取用户活跃趋势数据")
    @GetMapping("/active-trend")
    public Result<ChartDataVO> getActiveTrend(
            @RequestParam(defaultValue = "7") @Parameter(description = "天数，默认为7天",in = ParameterIn.QUERY) int days) {
        return Result.success(metricsService.getActiveTrend(days));
    }

    // 课程分布统计
    @Operation(summary = "获取课程分布统计", description = "获取课程的分布统计信息")
    @GetMapping("/course-distribution")
    public Result<List<NameValueVO>> getCourseDistribution() {
        return Result.success(metricsService.getCourseDistribution());
    }

    // 成绩分布统计
    @Operation(summary = "获取成绩分布统计", description = "根据课程ID获取成绩的分布统计信息")
    @GetMapping("/grade-distribution/{courseId}")
    public Result<List<NameValueVO>> getGradeDistribution(
            @PathVariable @Parameter(description = "课程ID",in = ParameterIn.PATH) Integer courseId) {
        return Result.success(metricsService.getGradeDistribution(courseId));
    }
}